package com.xdw.camerabyjava.slice;

import com.xdw.camerabyjava.ResourceTable;
import com.xdw.camerabyjava.TakePhotoAbility;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.aafwk.content.Operation;
import ohos.agp.components.Text;

public class MainAbilitySlice extends AbilitySlice {
    private Text takePhoto;
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);
        takePhoto = findComponentById(ResourceTable.Id_take_photo);
        takePhoto.setClickedListener(component -> {
            startAbility(TakePhotoAbility.class.getName());
//            startAbility("com.xdw.camerabyjava.TakePhotoAbility");
        });
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }

    private void startAbility(String abilityName) {
        Operation operation = new Intent.OperationBuilder()
                .withDeviceId("")
                .withBundleName(getBundleName())
                .withAbilityName(abilityName)
                .build();
        Intent intent = new Intent();
        intent.setOperation(operation);
        startAbility(intent);
    }
}
